package com.com.itext.day4;

import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.color.Color;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfString;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
import com.itextpdf.kernel.pdf.annot.PdfTextAnnotation;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

import java.io.FileNotFoundException;

public class demo1 {
    public static void main(String[] args) throws Exception {
        PdfWriter writer = new PdfWriter("D:\\测试pdf\\day4_1.pdf");
        PdfDocument pdf = new PdfDocument(writer);
        Document doc = new Document(pdf);
        //设置字体
        PdfFont font = PdfFontFactory.createFont("C:/Windows/Fonts/simyou.ttf", PdfEncodings.IDENTITY_H,true);
        doc.add(new Paragraph("我只是一个小小鸟想要飞也飞不高，寻寻觅觅").setFont(font).setFontSize(20).setFontColor(Color.BLUE));
        PdfAnnotation ann = new PdfTextAnnotation(new Rectangle(20,800,0,0))
                .setColor(Color.BLUE)
                .setTitle(new PdfString("ssfjkashdfjks"))
                .setContents("这是注释的内容")
                .setOpen(true);
        //注释添加到最前面
        pdf.getFirstPage().addAnnotation(ann);
        doc.close();

    }
}
